﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Text.RegularExpressions;

namespace Publicuse.Entity.AttributeUtil.Validate
{
    /// <summary>
    /// 手机号码验证
    /// </summary>
    public class MobileAttribute : BaseValidateAttribute
    {
        private string remark = null;
        private string format = null;
        public string GetRemark { get { return this.remark; } }

        /// <summary>
        /// 手机号码验证
        /// </summary>
        /// <param name="remark"></param>
        /// <param name="format"></param>
        public MobileAttribute(string remark, string format = @"^(13[0-9]|14[5|7]|15[0|1|2|3|5|6|7|8|9]|18[0|1|2|3|5|6|7|8|9])\d{8}$")
        {
            this.format = format;
            this.remark = remark;
        }


        public override bool Validate(object oValue)
        {
            if (oValue != null && !string.IsNullOrEmpty(oValue.ToString()))
            {
                return Regex.IsMatch(oValue.ToString(), this.format);
            }
            else
            {
                return true;
            }
        }
    }
}
